/* GUI CONVERTED from rcrp081.p (converter v1.76) Fri May  3 13:21:47 2002 */
/* rcrp081.p - Release Management Customer Schedules                    */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.7.2.7 $                                                 */
/*V8:ConvertMode=Report                                                 */
/* REVISION: 7.3    LAST MODIFIED: 01/09/95           BY: WUG *G0BY*    */
/* REVISION: 7.3    LAST MODIFIED: 04/11/95           BY: ame *F0QB*    */
/* REVISION: 7.4    LAST MODIFIED: 06/20/97           BY: *H19T* Seema Varma  */
/* REVISION: 8.5    LAST MODIFIED: 08/08/97           BY: *J1YQ* Suresh Nayak */
/* REVISION: 8.6    LAST MODIFIED: 10/07/97           BY: bvm *K0KV*          */

/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 06/28/00   BY: *N0DM* Mudit Mehta        */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb                */
/* REVISION: 9.1      LAST MODIFIED: 09/22/00   BY: *N0WD* Mudit Mehta        */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.7.2.6       BY: Patrick Rowan   DATE: 04/24/01  ECO: *P00G*    */
/* $Revision: 1.7.2.7 $      BY: Katie Hilbert   DATE: 04/15/02  ECO: *P03J*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* SHIPMENT HISTORY REPORT SUBPROGRAM */


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdeclre.i}
{cxcustom.i "RCRP081.P"}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */
{wbrp02.i}

define input parameter sodnbr like sod_nbr.
define input parameter sodline like sod_line.
define input parameter sodpart like sod_part.
define input parameter qty_inv as decimal.
define input parameter cum_qty as decimal.
define input parameter consigned as logical.

define shared variable date_from  as date label "Created" no-undo.
define shared variable date_to    as date label {t001.i} no-undo.
define shared variable ship_trans like mfc_logical
                                  label "Report Shipments" no-undo.
define shared variable rtn_trans  like mfc_logical
                                  label "Report Returns" no-undo.
define shared variable cum_trans  like mfc_logical
                                  label "Report Cum Adjs/Resets" no-undo.

define variable last_inv_nbr    as character initial ?.
define variable disp_time       as character format "x(5)" label "Time".
define variable invhist_qty_inv like idh_qty_inv.
define variable invhist_cum_qty like idh_cum_qty extent 0.
define variable old_db          as character.
define variable so_db           as character.
define variable sdb_err         as integer no-undo.
define variable disp-char       as character extent 10 no-undo.
define variable first_cn_ship   as logical no-undo.

define buffer rcttrans for tr_hist.
define buffer custad for ad_mstr.
define buffer shipad for ad_mstr.
define buffer dockad for ad_mstr.

assign
   disp-char[1]  = getTermLabelRtColon("SHIP-FROM",10)
   disp-char[2]  = getTermLabel("ORDER",5) + ":"
   disp-char[3]  = getTermLabel("LINE",4) + ":"
   disp-char[4]  = getTermLabelRtColon("CUSTOMER",10)
   disp-char[5]  = getTermLabelRtColon("SHIP-TO",10)
   disp-char[6]  = getTermLabelRtColon("DOCK",10)
   disp-char[7]  = getTermLabelRtColon("ITEM",10)
   disp-char[8]  = getTermLabelRtColon("PO_NUMBER",10)
   disp-char[9]  = getTermLabelRtColon("CUSTOMER_REFERENCE",10)
   disp-char[10] = getTermLabelRtColon("MODEL_YEAR",10).

FORM /*GUI*/ 
   tr_date
   disp_time
   tr_trnbr
   tr_type              format "x(9)"
   tr_userid
   tr_site              column-label "Site!Location"
   tr_serial            column-label "Lot/Serial!Reference"
                        format "x(24)"
   tr_qty_loc           column-label "Ship Qty"
   space(2)
   ih_inv_nbr
   idh_qty_inv          column-label "Inv/Adj Qty"
   idh_cum_qty[1]       column-label "Cum Ship Qty"
with STREAM-IO /*GUI*/  frame detail down width 132 no-box.

/* SET EXTERNAL LABELS */
setFrameLabels(frame detail:handle).

/* MOVE FRAME DEFINITION OUT OF DISPLAY */
/* STATEMENT BELOW TO A FORM STATEMENT  */

FORM /*GUI*/ 
   skip(1)
   disp-char[1] to 10 format "x(10)"
   si_site
   si_desc
   disp-char[2]       format "x(6)"
   sod_nbr
   disp-char[3]       format "x(5)"
   sod_line           format ">>>9"
   skip
   disp-char[4] to 10 format "x(10)"
   so_cust
   custad.ad_name
   skip
   disp-char[5] to 10 format "x(10)"
   so_ship
   shipad.ad_name
   disp-char[6] to 10 format "x(10)"
   sod_dock
   dockad.ad_name
   skip
   disp-char[7] to 10 format "x(10)"
   sod_part
   sod_custpart                  no-label
   pt_desc1
   skip
   disp-char[8] to 10 format "x(10)"
   sod_contr_id
   disp-char[9] to 10 format "x(10)"
   scx_custref
   disp-char[10] to 10 format "x(10)"
   scx_modelyr
   skip(1)
with STREAM-IO /*GUI*/  frame heading page-top width 132 no-box no-attr-space
   no-labels.

for each tr_hist no-lock
   {&RCRP081-P-TAG1}
    where tr_nbr = sodnbr
      and tr_line = sodline
      and tr_part = sodpart
      and (tr_type = "ISS-SO"  or tr_type = "CUM-SADJ" or
           tr_type = "CN-SHIP" or tr_type = "CUM-SRES")
      and (tr_date >= date_from or date_from = ?)
      and (tr_date <= date_to or date_to = ?)
      and
      (
      ship_trans and tr_type = "ISS-SO" and tr_qty_loc <= 0
      and (not consigned)
      or
      rtn_trans and tr_type = "ISS-SO" and tr_qty_loc > 0
      and (not consigned or (consigned and tr_ship_id <> ""))
      or
      cum_trans and tr_type begins "CUM"
      or
      tr_type = "CN-SHIP" and consigned and
      ((ship_trans and can-find(first rcttrans
        where rcttrans.tr_trnbr =
        integer(tr_hist.tr_rmks) and
        rcttrans.tr_qty_loc >= 0))
      or
      (rtn_trans and can-find(first rcttrans
       where rcttrans.tr_trnbr =
       integer(tr_hist.tr_rmks) and
       rcttrans.tr_qty_loc < 0)))
      )
      {&RCRP081-P-TAG2}
      use-index tr_nbr_eff
      break by tr_trnbr:
   if first(tr_trnbr) then do:
      find sod_det where sod_nbr = sodnbr and sod_line = sodline no-lock.
      find so_mstr where so_nbr = sodnbr no-lock.
      find scx_ref
         where scx_type = 1 and
               scx_order = sod_nbr and
               scx_line = sod_line
         no-lock no-error.
      find si_mstr where si_site = sod_site no-lock.
      find custad where custad.ad_addr = so_cust no-lock no-error.
      find shipad where shipad.ad_addr = scx_shipto no-lock no-error.

      find dockad where dockad.ad_addr = sod_dock no-lock no-error.
      find pt_mstr where pt_part = sod_part no-lock.

      display
         disp-char
         si_site
         si_desc
         sod_nbr
         sod_line
         so_cust
         scx_custref
         scx_modelyr

         if available custad
         then
            custad.ad_name
         else
            "" @ custad.ad_name
         scx_shipto @ so_ship

         if available shipad
         then
            shipad.ad_name
         else
            "" @ shipad.ad_name
         sod_dock

         if available dockad
         then
            dockad.ad_name
         else
            "" @ dockad.ad_name
         sod_part
         sod_custpart
         pt_desc1
         sod_contr_id
      with frame heading STREAM-IO /*GUI*/ .
   end.

  first_cn_ship = if (tr_type = "ISS-SO"   or
                      tr_type = "CUM-SADJ" or
                      tr_type = "CUM-SRES")
                  then false
                  else first_cn_ship.

   {&RCRP081-P-TAG3}
   if tr_type = "ISS-SO" then do:
      {&RCRP081-P-TAG4}
      display
         tr_date
         string(tr_time,"HH:MM") @ disp_time
         tr_trnbr
         getTermLabel("SHIPMENT",8) when (tr_qty_loc <= 0)
                                    @ tr_type
         getTermLabel("RETURN",8)   when (tr_qty_loc >  0)
                                    @ tr_type
         tr_userid
         tr_site
         tr_serial
         (- tr_qty_loc) @ tr_qty_loc
      with frame detail STREAM-IO /*GUI*/ .

      if tr_rmks <> last_inv_nbr then do:
         if tr_rmks = "" then
            display
               qty_inv @ idh_qty_inv
               cum_qty @ idh_cum_qty[1]
            with frame detail STREAM-IO /*GUI*/ .
         else do:
            /*GET THE QTY INVOICED AND CUM QTY SHIPPED FROM INV HISTORY FILE*/
            find so_mstr where so_nbr = tr_nbr no-lock.
            so_db = trim(substring(so_conrep,15,20)).

            if so_db <> global_db then do:
               old_db = global_db.

               {gprun.i ""gpalias3.p"" "(input so_db, output sdb_err)"}

               {gprun.i ""rcrp082.p""
                  "(input tr_rmks,
                    input sodnbr,
                    input sodline,
                    output invhist_qty_inv,
                    output invhist_cum_qty)"}

               {gprun.i ""gpalias3.p"" "(input old_db, output sdb_err)"}
            end.
            else do:
               {gprun.i ""rcrp082.p""
                  "(input tr_rmks,
                    input sodnbr,
                    input sodline,
                    output invhist_qty_inv,
                    output invhist_cum_qty)"}
            end.

            if invhist_qty_inv <> ? then
               display
                  tr_rmks format "x(8)" @ ih_inv_nbr
                  invhist_qty_inv       @ idh_qty_inv
                  invhist_cum_qty       @ idh_cum_qty[1]
               with frame detail STREAM-IO /*GUI*/ .
         end.
      end.

      down 1 with frame detail.

      display
         tr_loc @ tr_site
         tr_ref @ tr_serial
      with frame detail STREAM-IO /*GUI*/ .
   end.
   else
      if tr_type = "CUM-SADJ" then do:
         display
            tr_date
            string(tr_time,"HH:MM") @ disp_time
            tr_trnbr
            getTermLabel("CUM_ADJ",8) @ tr_type
            tr_userid
            tr_rmks @ tr_serial
            tr_qty_chg @ idh_qty_inv
            tr_loc_begin @ idh_cum_qty[1]
         with frame detail STREAM-IO /*GUI*/ .

         down 1 with frame detail.
      end.
   else
      if tr_type = "CUM-SRES" then do:
         display
            tr_date
            string(tr_time,"HH:MM") @ disp_time
            tr_trnbr
            getTermLabel("CUM_RESET",9) @ tr_type
            tr_userid
            tr_rmks @ tr_serial
            tr_qty_chg @ idh_qty_inv
            tr_loc_begin @ idh_cum_qty[1]
         with frame detail STREAM-IO /*GUI*/ .

         down 1 with frame detail.
      end.

   /* CONSIGNED SHIPMENT */
   if tr_type = "CN-SHIP" then do:

      for first rcttrans where
         rcttrans.tr_trnbr = integer(tr_hist.tr_rmks)
      no-lock:

      if ship_trans and rcttrans.tr_qty_loc >= 0 then
         display
            tr_hist.tr_date
            string(tr_hist.tr_time,"HH:MM") @ disp_time
            tr_hist.tr_trnbr
            tr_hist.tr_type
            tr_hist.tr_userid
            tr_hist.tr_site
            tr_hist.tr_serial
            rcttrans.tr_qty_loc @ tr_hist.tr_qty_loc
         with frame detail STREAM-IO /*GUI*/ .

      if rtn_trans and rcttrans.tr_qty_loc < 0 then
         display
            tr_hist.tr_date
            string(tr_hist.tr_time,"HH:MM") @ disp_time
            tr_hist.tr_trnbr
            tr_hist.tr_type
            tr_hist.tr_userid
            tr_hist.tr_site
            tr_hist.tr_serial
            rcttrans.tr_qty_loc @ tr_hist.tr_qty_loc
         with frame detail STREAM-IO /*GUI*/ .

      if first_cn_ship = false then do:
         display
            qty_inv @ idh_qty_inv
            cum_qty @ idh_cum_qty[1]
         with frame detail STREAM-IO /*GUI*/ .
         first_cn_ship = true.
      end.  /* if first_cn_ship */

      down 1 with frame detail.

      display
         tr_hist.tr_loc @ tr_hist.tr_site
         tr_hist.tr_ref @ tr_hist.tr_serial
      with frame detail STREAM-IO /*GUI*/ .

      end.  /* for first rcttrans */
   end.  /* if tr_type = "CN-SHIP" */

   down 1 with frame detail.

   if last(tr_trnbr) then do:
      hide frame heading.
      page.
   end.

   if tr_type = "CN-SHIP" then
      last_inv_nbr = "".
   else
      last_inv_nbr = tr_rmks.

   
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/

end.
{wbrp04.i}
